var utils = new function() {
	
return {
    goToEdit : function(item) {
      popupManager.setCurrentTerm(Voc.getTerm($(item).data('id')));
      popupManager.nextView('#editView');
    },

	// Refresh list if global array of terms has been changed
	refreshList: function() {
		var lis = '';
		for (key in localVoc) {
			var className = '';
			if (!localVoc[key].isReadyToUse)
				className += 'not-ready';
			lis += '<li><a href="#" class="'+className+'" data-id="'+localVoc[key].id+'" onclick="utils.goToEdit(this); return false;">'+localVoc[key].value+'</a></li>'
		}
		$('#mainList').html(lis);
	},
	
	updateBadge : function(count) {
	  chrome.browserAction.setBadgeText({text : count + ''});
	  chrome.browserAction.setBadgeBackgroundColor({color : [0, 255, 0, 255]});
	},
	
	goToStatistics : function() {
		var knowledgPer = 0;
		var count = Voc.getCount();
		Voc.each(function(term) {
			if (0 == term.repeatCount) { 
				count--;
			} else {				
				knowledgPer += term.successCount/term.repeatCount
			}
		});
		knowledgPer = knowledgPer/count;
		var rest = 1 - knowledgPer;
		$("#statistics img").attr("src", "https://chart.googleapis.com/chart?cht=p&chs=255x200&chd=t:"+rest+","+knowledgPer+"&chl=Purely%20known|Well%20known&chco=#592003|#F8893F");
		popupManager.nextView("#statistics");
	}
	
	}
}